import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/material.dart';


import '../../resources/kq_theme_colors.dart';

/// 标签控件
///
/// 圆角边框(实线或虚线) + 文字
///
/// @author 周卓
///
class KqTagView extends StatelessWidget {

  /// 文字
  final String text;
  /// 字体大小，默认14
  final double? fontSize;
  /// 内边距
  final EdgeInsets? padding;
  /// 是否虚线，默认false
  final bool dashLine;
  /// 文字颜色，默认黄色
  final Color textColor;
  /// 边框颜色，默认黄色
  final Color borderColor;
  /// 背景颜色，默认透明
  final Color backgroundColor;
  /// 圆角，默认3
  final double? radius;

  const KqTagView(
      {Key? key,
      required this.text,
      this.padding,
      this.dashLine = false,
      this.fontSize,
      this.textColor = KqThemeColors.textYellow,
      this.borderColor = KqThemeColors.textYellow,
      this.backgroundColor = KqThemeColors.bgTransparent,
      this.radius})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return dashLine
        ? DottedBorder(
            borderType: BorderType.RRect,
            strokeWidth: 1,
            padding: const EdgeInsets.all(0.5),
            color: borderColor,
            borderPadding: const EdgeInsets.only(bottom: 0.5),
            radius: Radius.circular(radius ?? 2),
            child: ClipRRect(
              borderRadius: BorderRadius.all(Radius.circular(radius ?? 2)),
              child: Container(
                color: backgroundColor,
                padding: padding ??
                    EdgeInsets.symmetric(horizontal: 6, vertical: 4),
                child: Text(
                  text,
                  style: TextStyle(
                      fontSize: fontSize ?? 12, color: textColor),
                ),
              ),
            ),
          )
        : Container(
            padding:
                padding ?? EdgeInsets.symmetric(horizontal: 6, vertical: 4),
            decoration: BoxDecoration(
                color: backgroundColor,
                borderRadius: BorderRadius.all(Radius.circular(radius ?? 2)),
                border: Border.all(width: 1, color: borderColor)),
            child: Text(
              text,
              style: TextStyle(
                  fontSize: fontSize ?? 12, color: textColor),
            ),
          );
  }
}
